<?php
/**
 * 后台管理统一调用入口
 *
 * Created		: 2010-09-13
 * Modified		: 2011-09-12
 * @link		: http://www.topews.com
 * @copyright	: (c) 2011
 * @version	: 0.1.0
 * @author		: Joseph Chen (Jsph.chen@gmail.com)
 */
$admin_root = dirname(__FILE__) . DS;
//根据参数指定载入相应模块
$mo = empty($_GET['mo']) ? 'index' : $_GET['mo'];
$moPos = $mo;
$block = empty($_GET['block']) ? 'base' : $_GET['block'];

//不是管理员跳转到登录页面
if ($mo!='login' && empty($_SESSION['is_admin'])) {
	$redirect = '?mo=login&url=' . urlencode($_SERVER['REQUEST_URI']);
	header('Location: ' . $redirect);
	exit;
}

// 后台页面不需要任何缓存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

L('admin');

$vars = array(
	'app_theme'   => $app_view.'Admin/'.$adminThemeSign.'/',
	'suffix_tpl'  => $suffix_tpl,
	'theme'       => '',
	'theme_dir'   => '',
	'app_cache_tpl' => $app_cache_tpl.'Admin/'.$adminThemeSign.'/',
);

$css = array();
App::setOptions($vars);

//初始化更多的服务器信息
if ($mo=='index')
{
	
} else {
	
}


$cur_lang = isset($_COOKIE['cur_lang']) ? $_COOKIE['cur_lang'] : 'zh-cn';
$langList = App::getOpenedLang();



$item = empty($_GET['item']) ? 'create' : trim($_GET['item']);

$mo_file = $admin_root.$mo.'.php';

if ($mo == 'phpinfo') {
	phpinfo();
	exit;
} elseif (!is_file($mo_file)) {//不存在指定模块的程序,则给出相应的提示
	$mo_result = false;
	$g_msg = array(
		'type' => 'Error',
		'desc' => sprintf($GLOBALS['ModuleIsNotExist'], $mo)
	);
} elseif ($mo != 'index') {
	// 统一处理URL中的id参数
	if (isset($_GET['id'])) {
		$id = $_GET['id'] = (int)$_GET['id'];
	} else {
		$id = $_GET['id'] = 0;
	}
	if (!is_file($mo_file)) {
		echo $mo_file.' is not exist!';
		exit;
	}
	$mo_result = include_once $mo_file;
} else {
	$mo_result = true;
}

if (false === $mo_result) {
	$mo_tpl = 'msg';
} elseif (empty($mo_tpl)) {
	$mo_tpl = $mo;
}

if ($mo_tpl == 'msg') {
	$curPos = $GLOBALS['CurrentList']['msg'];
} else if (isset($GLOBALS['CurrentList'][$moPos])) {
	$curPos = $GLOBALS['CurrentList'][$moPos];
} else {
	$curPos = $GLOBALS['CurrentList']['unknow'];
}



if ($mo=='login')
{
	App::view('login');
} elseif (isset($hf)) {
	App::view($hf, $mo_tpl);
} else {
	App::view(1, $mo_tpl);
}

